#============================================================
#    Input Utils
#============================================================
# - datetime: 2022-09-19 23:08:46
#============================================================
class_name InputUtil


##  是否点击了左键
##[br]
##[br][code]event[/code]  事件对象
##[br][code]pressed[/code]  是否按下
static func is_click_left(event: InputEvent, pressed := true) -> bool:
	if event is InputEventMouseButton:
		return event.button_index == MOUSE_BUTTON_LEFT and event.pressed == pressed
	return false

##  是否点击了右键
##[br]
##[br][code]event[/code]  事件对象
##[br][code]pressed[/code]  是否按下
static func is_click_right(event: InputEvent, pressed := true) -> bool:
	if event is InputEventMouseButton:
		return event.button_index == MOUSE_BUTTON_RIGHT and event.pressed == pressed
	return false

##  是否点击了中键
##[br]
##[br][code]event[/code]  事件对象
static func is_click_middle(event: InputEvent) -> bool:
	if event is InputEventMouseButton:
		return event.button_index == MOUSE_BUTTON_MIDDLE and event.pressed
	return false

##  是否双击
##[br]
##[br][code]event[/code]  事件对象
static func is_double_click(event: InputEvent):
	if event is InputEventMouseButton:
		return event.button_index == MOUSE_BUTTON_LEFT and event.pressed and event.double_click
	return false


##  点击 Control 节点时执行方法
##[br]
##[br][code]node[/code]  点击的节点
##[br][code]callable[/code]  回调方法
static func click_control(node: Control, callable: Callable):
	node.gui_input.connect(func(event):
		if is_click_left(event):
			callable.call()
	)

